/*
 * ProcessInfo.java
 *
 * $Id: ProcessInfo.java,v 1.1 2008-03-18 12:58:46 mario Exp $
 */
package org.ceteca.explica.core.traceability.tree;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * ValueObject with the data of a Process item.
 * <br/>
 * Responsibilities:
 * <ul>
 *  <li>Store the process data.</li>
 * </ul>
 * <br/>
 * @author Mario García García <mario@imagos.es>
 * Copyright (c) 2007 Fundación Centro Tecnolóxico da Carne
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <br/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <br/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class ProcessInfo {
	/** Process date */
	private String dateProcess;
	/** Process code */
	private String codOperation;
	/** List of input products to the process */
	private ArrayList lIn;
	/** List of workers involved in the process */
	private ArrayList lWorkers;
	/** List of workcenters where the process has taken place */
	private ArrayList lWorkcenters;
	/** List of operations of the process */
	private ArrayList lOperations;
	/** List of comments linked to the process */
	private ArrayList lComments;
	
	/**
	 * Default ProcessInfo constructor.
	 */
	public ProcessInfo() {
		this.setDateProcess(null);
		this.setCodOperation(null);
	}

	/**
	 * ProcessInfo constructor that initializes the process values.
	 * @param dateProcess String, process date.
	 * @param codOperation String, process code.
	 */
	public ProcessInfo(String dateProcess, String codOperation) {
		this.setDateProcess(dateProcess);
		this.setCodOperation(codOperation);
	}
	
	/**
	 * Gets the list of input products for the process.
	 * @return ArrayList, list of input products.
	 */
	public ArrayList getLIn() {
		return lIn;
	}
	/**
	 * Sets up the input list of products for the process.
	 * @param in ArrayList, list of input products.
	 */
	public void setLIn(ArrayList in) {
		lIn = in;
	}
	/**
	 * Adds a new product to the input process list.
	 * @param p ProductInfo, input product's data to insert.
	 */
	public void addIn(ProductInfo p) {
		if (lIn == null)
			lIn = new ArrayList();
		lIn.add(p);
	}
	/**
	 * Removes a product from the input process list.
	 * @param p ProductInfo, input product's data to delete.
	 */
	public void delIn(ProductInfo p) {
		if (lIn != null && lIn.size() > 0) {
			lIn.remove(p);
		}
	}
	
	/**
	 * Gets the list of operations of the process.
	 * @return ArrayList, list of operations.
	 */
	public ArrayList getLOperations() {
		return lOperations;
	}
	/**
	 * Sets up the list of operations of the process.
	 * @param ope ArrayList, list of operations.
	 */
	public void setLOperations(ArrayList ope) {
		lOperations = ope;
	}
	/**
	 * Adds a new operation to the process operations' list.
	 * @param ope String, operation's data to insert.
	 */
	public void addOperation(String ope) {
		if (lOperations == null)
			lOperations = new ArrayList();
		lOperations.add(ope);
	}
	
	/**
	 * Gets the list of workers involved in the process.
	 * @return ArrayList, list of workers.
	 */
	public ArrayList getLWorkers() {
		return lWorkers;
	}
	/**
	 * Sets up the list of workers involved in the process.
	 * @param per ArrayList, list of workers.
	 */
	public void setLWorkers(ArrayList per) {
		lWorkers = per;
	}
	/**
	 * Adds a new worker to the process workers' list.
	 * @param worker WorkerInfo, worker's data to insert.
	 */
	public void addWorker(WorkerInfo worker) {
		if (lWorkers == null)
			lWorkers = new ArrayList();
		lWorkers.add(worker);
	}
	/**
	 * Removes a worker from the process workers' list.
	 * @param w WorkerInfo, worker's data to delete.
	 */
	public void delWorker(WorkerInfo w) {
		if (lWorkers != null && lWorkers.size() > 0) {
			lWorkers.remove(w);
		}
	}
	
	/**
	 * Gets the list of comments linked to the process.
	 * @return ArrayList, list of comments.
	 */
	public ArrayList getLComments() {
		return lComments;
	}
	/**
	 * Sets up the input list of comments linked to the process.
	 * @param com ArrayList, list of comments.
	 */
	public void setLComments(ArrayList com) {
		lComments = com;
	}
	/**
	 * Adds a new comment to the process comments' list.
	 * @param comment String, comment's data to insert.
	 */
	public void addComment(String comment) {
		if (lComments == null)
			lComments = new ArrayList();
		lComments.add(comment);
	}
	/**
	 * Adds a list of comments to the process comments' list.
	 * @param comments ArrayList<String>, comments' list to insert.
	 */
	public void addComments(ArrayList<String> comments) {
		if (lComments == null)
			lComments = new ArrayList();
		lComments.addAll(comments);
	}
	/**
	 * Removes a comment from the process comments' list.
	 * @param c String, comment's data to delete.
	 */
	public void delComment(String c) {
		if (lComments != null && lComments.size() > 0) {
			lComments.remove(c);
		}
	}

	/**
	 * Gets the list of workcenters of the process.
	 * @return ArrayList, list of workcenters.
	 */
	public ArrayList getLWorkcenters() {
		return lWorkcenters;
	}
	/**
	 * Sets up the list of workcenters of the process.
	 * @param lWorkcenters ArrayList, list of workcenters.
	 */
	public void setLWorkcenters(ArrayList lWorkcenters) {
		this.lWorkcenters = lWorkcenters;
	}
	/**
	 * Adds a new workcenter to the process workcenters' list.
	 * @param workcenter WorkcenterInfo, workcenter's data to insert.
	 */
	public void addWorkcenter(WorkcenterInfo workcenter) {
		if (lWorkcenters == null)
			lWorkcenters = new ArrayList();
		lWorkcenters.add(workcenter);
	}
	/**
	 * Removes a workcenter from the process workcenters' list.
	 * @param w WorkcenterInfo, workcenter's data to delete.
	 */
	public void delWorkcenter(WorkcenterInfo w) {
		if (lWorkcenters != null && lWorkcenters.size() > 0) {
			lWorkcenters.remove(w);
		}
	}
	
	/**
	 * Gets the process date.
	 * @return String, process date.
	 */
	public String getDateProcess() {
		return dateProcess;
	}
	/**
	 * Sets up the process date.
	 * @param dateProcess String, a date.
	 */
	public void setDateProcess(String dateProcess) {
		this.dateProcess = dateProcess;
	}

	/**
	 * Gets the process code.
	 * @return String, process code.
	 */
	public String getCodOperation() {
		return codOperation;
	}
	/**
	 * Sets up the process code.
	 * @param codOperation String, an operation code.
	 */
	public void setCodOperation(String codOperation) {
		this.codOperation = codOperation;
	}
	
	/**
	 * Converts the process info to a formatted String.
	 * @return String, formatted String with the process's data.
	 */
	public String toString() {
		StringBuffer result = new StringBuffer();
		result.append("PROCESS No: ");
		result.append(this.codOperation);
		result.append("   (");
		result.append(this.dateProcess);
		result.append("):");
		result.append("\n");
		if (this.lIn != null) {
			result.append("\n");
			result.append("----------");
			result.append("\n");
			Iterator it = lIn.iterator();
			while (it != null && it.hasNext()) {
				result.append("\n");
				result.append(it.next());
				result.append("\n");
				result.append("·$.$.$.$.$.$");
			}
			result.append("\n");
			result.append("----------");
		}
		
		if (this.lWorkers != null) {
			result.append("\n");
			result.append("##########");
			result.append("\n");
			Iterator it = lWorkers.iterator();
			while (it != null && it.hasNext()) {
				result.append("\n");
				result.append(it.next());
				result.append("\n");
				result.append("·$.$.$.$.$.$");
			}
			result.append("\n");
			result.append("##########");
		}
		
		if (this.lWorkcenters != null) {
			result.append("\n");
			result.append("··········");
			result.append("\n");
			Iterator it = lWorkcenters.iterator();
			while (it != null && it.hasNext()) {
				result.append("\n");
				result.append(it.next());
				result.append("\n");
				result.append("·$.$.$.$.$.$");
			}
			result.append("\n");
			result.append("··········");
		}
		
		if (this.lOperations != null) {
			result.append("\n");
			result.append("@@@@@@@@@@");
			result.append("\n");
			Iterator it = lOperations.iterator();
			while (it != null && it.hasNext()) {
				result.append("\n");
				result.append(it.next());
				result.append("\n");
				result.append("·$.$.$.$.$.$");
			}
			result.append("\n");
			result.append("@@@@@@@@@@");
		}
		
		if (this.lComments != null) {
			result.append("\n");
			result.append("-.-.-.-.-.");
			result.append("\n");
			Iterator it = lComments.iterator();
			while (it != null && it.hasNext()) {
				result.append("\n");
				result.append(it.next());
				result.append("\n");
				result.append("·$.$.$.$.$.$");
			}
			result.append("\n");
			result.append("-.-.-.-.-.");
		}
		
		
		return result.toString();
	}
	
	/**
	 * Updates the process data.
	 * @param info ProcessInfo, new process data.
	 */
	public void update(ProcessInfo info) {
		this.setCodOperation(info.getCodOperation());
		this.setDateProcess(info.getDateProcess());
	}
	
	/**
	 * Returns tag Id assigned to CVS source file.
	 */
	public static String getRevision() {
		return "$Id: ProcessInfo.java,v 1.1 2008-03-18 12:58:46 mario Exp $";
	}
}
